﻿module InputHandlerModule

open SI
open Math
open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Input

type Input = 
    {
        mutable leftMousePressed    : bool
        mutable mousePosition       : Vector2<pixel>
    }

type InputHandler = 
    {
        mutable mInput              : Input
        mutable mMouseStateBefore   : ButtonState
    }

    static member Init() = 
        let handler =
            {
                mInput = 
                    {
                        leftMousePressed = false
                        mousePosition = Vector2<pixel>(0.f<pixel>,0.f<pixel>)
                    }
                mMouseStateBefore = ButtonState.Released
            }
        handler

    member this.Update(iTime) = 
        if (this.mMouseStateBefore = ButtonState.Pressed) then
            if (Mouse.GetState().LeftButton = ButtonState.Released) then
                this.mInput.leftMousePressed <- true;
        else
            this.mInput.leftMousePressed <- false;
        this.mInput.mousePosition.X <- float32(Mouse.GetState().X) * 1.f<pixel>;
        this.mInput.mousePosition.Y <- float32(Mouse.GetState().Y) * 1.f<pixel>;
        this.mMouseStateBefore <- Mouse.GetState().LeftButton;


let mutable inputHandler = InputHandler.Init()

